$(function(){  	
  	colspanTable(); 
  	initAuthor();
});
//功能名称checkBox全选事件
$("input[name$='listCmenu']").change(function(){
	if($(this).attr("checked")) {
		$(this).parent().next().children("input[name$='listOperId']").attr("checked",true);
	}else{
		$(this).parent().next().children("input[name$='listOperId']").attr("checked",false);
	}
});

function colspanTable(){
   try{
   	  var tables = document.getElementById("authrosTable");
   	  var tableLen = tables.rows.length;
   	  var tmp1 = "-1";
   	  var pos1=1;
   	  for(var i = 1;i<tableLen;i++){
   	     if(tables.rows[i].cells[0].innerHTML==tmp1){
   	     	tables.rows[pos1].cells[0].rowSpan++;
			tables.rows[i].cells[0].style.display='none';
   	     }else{
   	     	 tmp1 = tables.rows[i].cells[0].innerHTML;
			 pos1 = i;
   	     }
   	  }
   }catch(e){
     alert(e.message);
   }
}
$("#menu_save_btn").click(function(){
   var roleId = $("#roleId").val();
   var count = checkChangedOnly("listOperId");
   if(isEmpty(roleId)){
      $.messager.alert("系统提示", "请选择角色！","warning");
      return;
   }
   if(count==0){
     $.messager.alert("系统提示", "请选择功能权限！","warning");
     return;
   }
   //return;
   submitForm({
      formId:'saveForm',
      url:'role.do?method=auhorRole',
      callback:function(msg){
         if(msg=="SUCCESS"){   	   	  
   	  		$.messager.alert("系统提示","授权成功！","info",function(){
   	  		   parent.reloadTable({tableId:'roles'});
   	  		   parent.$('#authorWin').window('close');
   	  		});
		 }else if(msg=="FAIL"){   	  
		   	$.messager.alert("系统提示","授权失败，请重试！","error");
		 }else{
		   	$.messager.alert("系统提示","授权时系统异常："+msg,"error");	
		 }
      }
   });
});
function initAuthor(){
   var roleId = $("#roleId").val();
   var url = "role.do?method=queryFuncOperAuthor";
   $.post(url,{"roleId":roleId,"version":Math.random()},function(data){
      paraJson(data);
   },'json');
}
function paraJson(data){
   var error = data.errors;
   if(error!="1" && error!="0"){
      $.messager.alert("系统提示",error,"error");   	
   }else if(error=='0'){
      var list = data.rows;
      var len = list.length;
      for(var i = 0;i<len;i++){
         var operaId = list[i].operaId;
         $("#base_"+operaId).attr("checked","checked");
      }
   }
}